#include<iostream>
#include<string>
#include <stack>
using namespace std;
class Parenthesis {
public:
    bool chkParenthesis(string A, int n) {
        // write code here
        stack<char> s1;
        for (size_t i = 0; i < n; ++i) {
            if (A[i] == '(') {
                s1.push(A[i]);
            }
            else if (A[i] == ')' && !(s1.empty()) && s1.top() == '(') {
                s1.pop();
            }
            else {
                return false;
            }
        }
        return true;
    }
};
int main() {
    string A("())()()(((d");
    Parenthesis p;
    cout << p.chkParenthesis(A, A.size()) << endl;
    return 0;
}